﻿// Write a program that reads an integer number and calculates and prints its square root. 
// If the number is invalid or negative, print "Invalid number". 
// In all cases finally print "Good bye". Use try-catch-finally.

using System;

public class CalcSquareRoot
{
    public static double GetSquareRoot(string consoleInput)
    {
        uint number;
        if (!uint.TryParse(consoleInput, out number))
        {
            throw new FormatException("Invalid number");
        }

        if (number < 0)
        {
            throw new ArgumentOutOfRangeException("Invalid number");
        }

        return Math.Sqrt(number);
    }

    private static void Main()
    {
        Console.Write("Enter integer number: ");
        string consoleInput = Console.ReadLine();
        try
        {
            double squareRoot = GetSquareRoot(consoleInput);
            Console.WriteLine("SQRT({0}) = {1}", consoleInput, squareRoot);
        }
        catch (SystemException se)
        {
            Console.WriteLine(se.Message);
        }
        finally
        {
            Console.WriteLine("Good bye");
        }
    }
}